%%作出函数的图像
%y = sin(x)与y = cos(x)与y = sin(2*x)图像
x1 = 0:0.1:2*pi;
y1 = sin(x1);
x2 = linspace(0,2*pi,50);
y2 = cos(x2);
subplot(2,2,1)
plot(x1,y1,'ro',x2,y2,'b+')
%sin(2*x)的图像
subplot(2,2,2);
fun='sin(2*x)';
fplot(fun,[0,2*pi]);
%sin(x)的图像
subplot(2,2,3);
fun1='sin(x)';
fplot(fun1,[0,2*pi]);
%cos( x)的图像
subplot(2,2,4);
fun2 = 'cos(x)';
fplot(fun2,[0,2*pi]);
%%
%图形的说明与定制命令
title a
xlabel = x;ylabel = fun2;
hold on
grid on
subplot(2,2,4);
fun2 = 'cos(x)';
fplot(fun2,[0,2*pi]);
%%
%作出方程x^4+y^4 = 1所表示的图像
syms x y
subplot(1,2,1);
ezplot(x^4+y^4-1,[-1,1]);
%%
%作出x^4+y^4-8x^2-10y^2+16=0的图像
syms x y
f = x^4+y^4-8*x^2-10*y^2+16;
subplot(1,2,2);
ezplot(f)%当不好估计它的范围的时候，直接进行函数的输出即可
%%
%输出2.1.5将里面的函数都放在一张图上
t = 0:0.1:2*pi;
x1 = sin(t);
y1 = cos(t);
x2 = 2*sin(2*t);
y2 = 2*cos(3*t);
plot(x1,y1,'b*',x2,y2,'k--');
%%
%2.1.6
t= 0:0.1:2*pi;
y1 = 5*cos(2*t);
y2 = 5*cos(3*t);
subplot(1,2,1),polar(t,y1),
subplot(1,2,2),polar(t,y2)
%%
%2.1.6
theat = 0:0.1:2*pi;
rho1 = 5*cos(2*theat);
rho2 = 5*cos(3*theat);
subplot(1,2,1),polar(theat,rho1),
subplot(1,2,2),polar(theat,rho2)
%%
%2.1.7
t = 0:0.1:20;
r = exp(-0.2*t);
th = 0.5*pi*t;
x = r.*cos(th);y = r.*sin(th);
z = sqrt(t);
plot3(x,y,z);
title 'a';
text(x(end),y(end),z(end),'end');
xlabel('\it x=e^{\rm-0.2\it t\rm}cos(\it\pit\rm/2)');
ylabel('y');
zlabel('z');
axis([-1 1 -1 1 0 4]);
grid on
%%
%2.1.8
x = -5:0.1:5;
f = fenduan1(x);
plot(x,f,x,f,'ro');


%%
function y = fenduan1(x)
n = length(x);
for i = 1:n
    if(x(i)>1)
        y(i) = x(i)^2;
    elseif(x(i)<=-1)
        y(i) = 3+2*x(i);
    else
        y(i) = 1;
    end
end
end


























